package org.tc.feign.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.tc.client.entity.Shoppingcar;
import org.tc.feign.client.service.FeignShopCarService;

import java.util.List;

@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.OPTIONS})
@RestController
public class FeignShopCarController {

    @Autowired
    private FeignShopCarService shoppingcarService;

    /**
     * 添加商品到购物车
     *
     * @param shoppingcar
     * @return
     */
    @RequestMapping("/insertShopCar")
    public int insertShopCar(@RequestBody Shoppingcar shoppingcar) {
        System.out.println("添加购物车");
        return shoppingcarService.insertShopCar(shoppingcar);
    }

    /**
     * 根据用户信息查询购物车所有商品
     *
     * @param userid
     * @return
     */

    @RequestMapping("/selectShopByUserId")
    public List<Shoppingcar> selectShopByUserId(Integer userid) {
        System.out.println("用户" + userid + ":的购物车");
        return shoppingcarService.selectShopCarByUserId(userid);
    }

    /**
     * 根据id删除购物车内商品
     *
     * @param id
     * @return
     */
    @RequestMapping("/deleteShopCarById")
    public int deleteShopCarById(Integer id) {
        System.out.println("删除购物车商品");
        return shoppingcarService.deleteShopCarById(id);
    }

    @RequestMapping("/getShopByState")
    public List<Shoppingcar> getShopByState(@RequestBody Shoppingcar shoppingcar) {
        List<Shoppingcar> list = shoppingcarService.getShopByState(shoppingcar);
        return list;
    }

    @RequestMapping("/updShopState")
    public int updShopState(@RequestBody Shoppingcar shoppingcar) {
        int count = shoppingcarService.updShopState(shoppingcar);
        return count;
    }

}
